package egg_drop;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.Random;

public class AnimGoose {
    
    public int x;
    
    public int y;    
   
    private int speed;
   
    private BufferedImage GooseImg;      
    
    private int GooseImgWidth;
    
    private int GooseImgHeight;
    
    private boolean left;
    
    private int swapInterval;
    
    public AnimGoose(int x, int y, int speed, BufferedImage GooseImg)
    {
        this.x = x;
        this.y = y;
        
        this.speed = speed;
        
        this.GooseImg = GooseImg;
        
        GooseImgWidth = GooseImg.getWidth();
        GooseImgHeight = GooseImg.getHeight();
        
        swapInterval = 0;
        
    }
    
    public void Update()
    {
    	Random random = new Random();
    	if ((x + GooseImgWidth + 50) >= Framework.frameWidth && left == false)
			left = true;
		if ((x - GooseImgWidth <= 0) && left == true)
			left = false;
		if ((swapInterval >= 30)){
			left = random.nextBoolean();
			swapInterval = 0;
		}
		if (!left)
		{
			x += speed;
		}
		else
		{
			x -= speed;
		}
		y = 0;
		swapInterval +=1;
    }
    
    public void Draw(Graphics2D g2d)
    {
        g2d.drawImage(GooseImg, x, y, null);
    }
}

/**package egg_drop;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;

public class AnimGoose {
	
	private Random random;
	
	private int swapInterval;
	
	private boolean left;

	public int x;
	
	public int y;
	
	public int gooseSpeed;
	
	private BufferedImage gooseImg;
	
	public int gooseImgWidth;
	
	public int gooseImgHeight;
	
	public AnimGoose()
	{
		Initilize();
		LoadContent();
	}
	
	private void Initilize()
	{
		random = new Random();
		
		Resetgoose();
		
		
	}
	
	private void LoadContent()
	{
		try {		
			
			URL gooseImgUrl = this.getClass().getResource("/egg_drop/resources/goose.png");
			gooseImg = ImageIO.read(gooseImgUrl);
			gooseImgWidth = gooseImg.getWidth();
			gooseImgHeight = gooseImg.getHeight();
			}
			catch(IOException ex) {
	            Logger.getLogger(ObBasket.class.getName()).log(Level.SEVERE, null, ex);
	        }
	}
	
	public void Resetgoose()
	{
		x = Framework.frameWidth/2;
		y = 0;
		left = false;
		swapInterval = 0;
		
		gooseSpeed = 3;
	}
	
	public void Update()
	{
		if ((x + gooseImgWidth + 50) >= Framework.frameWidth && left == false)
			left = true;
		if ((x - gooseImgWidth <= 0) && left == true)
			left = false;
		if ((swapInterval >= 30)){
			left = random.nextBoolean();
			swapInterval = 0;
		}
		if (!left)
		{
			x += gooseSpeed;
		}
		else
		{
			x -= gooseSpeed;
		}
		y = 0;
		swapInterval +=1;
	}
	
	public void Draw(Graphics2D g2d)
	{
		g2d.drawImage(gooseImg, x, y, null);
	}
	
	
}
*/